package cn.edu.scau.cmi.chenruilin.singleton;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.chenruilin.multipattern.Marshal;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.control.Label;

public class Controller {

    @FXML
    private TextField input;

    @FXML
    private Button button2;

    @FXML
    private Button reset;

    @FXML
    private Label output;

    @FXML
    private Button button1;
    
    public int flag1 = 0;
    public int flag2 = 0;
    public int flag3 = 0;
    @FXML
    public void setSingleton() {
    	if(flag1 == 0) {
    		output.setText("当前是单例模式\n");
    		flag1 = 1;
    	}
    	String name = input.getText();
    	Chairman chairman = Chairman.getInstance(name);
    	output.setText(output.getText() + "\n" + chairman.toString());
    }

    @FXML
    public void setMpattern() {
    	if(flag2 == 0) {
    		output.setText("当前是多例模式\n");
    		flag2 = 1;
    	}
    	String name = input.getText();
    	List<Marshal> marshal = Marshal.getInstance(name);
    	String content = null;
    	if(flag3 == 0) {
    		for(int i= 0; i < marshal.size(); i++) {
        		content = output.getText() + "\n" + marshal.get(i);
        	}
    	}
    	else content = output.getText();
    	if(marshal.size() == 10 && flag3 == 0) {
    		flag3 = 1;
    		content = content + "\n当前已经创建十个元帅了，不能再创建了！";
    	}
    	output.setText(content);
    }

    @FXML
    public void setReset() {
    	Chairman.reset();
    	Marshal.reset();
    	output.setText("");
    	flag1 = flag2 = flag3 = 0;
    }

   
}
